package cn.dujc.superkid.fragment.research;

import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;


import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import cn.dujc.core.adapter.BaseQuickAdapter;
import cn.dujc.core.ui.BaseListFragment;
import cn.dujc.core.util.ToastUtil;
import cn.dujc.superkid.R;
import cn.dujc.superkid.activities.CourseExamActivity;
import cn.dujc.superkid.activities.CourseVideoActivity;
import cn.dujc.superkid.activities.LoginActivity;
import cn.dujc.superkid.adapter.MyQuestionAdapter;
import cn.dujc.superkid.adapter.OnlineAnswerAdapter;
import cn.dujc.superkid.adapter.TeacherAdapter;
import cn.dujc.superkid.api.HttpHelper;
import cn.dujc.superkid.api.QMap;
import cn.dujc.superkid.api.Result;
import cn.dujc.superkid.api.ResultCallBack;
import cn.dujc.superkid.bean.ContactResult;
import cn.dujc.superkid.bean.ExamineListResult;
import cn.dujc.superkid.bean.Main2Entity;
import cn.dujc.superkid.bean.RegisterResult;
import cn.dujc.superkid.bean.TeacherResult;
import cn.dujc.superkid.bean.VideoListResult;
import cn.dujc.superkid.utils.OnMultiClickListener;
import cn.dujc.superkid.utils.Preferences;
import retrofit2.Call;
import retrofit2.http.QueryMap;

/**
 * @author du
 * date 2018/8/2 上午12:11
 */
public class TeachersFragment extends BaseListFragment {
    private List<Object> dataList=new ArrayList<>();
    private TeacherAdapter teacherAdapter;


    @Nullable
    @Override
    protected BaseQuickAdapter initAdapter() {
        teacherAdapter = new TeacherAdapter(dataList);
        return teacherAdapter;

    }

    protected void recyclerViewOtherSetup() {
        if (dataList != null) {
            //去掉下划线
//            mRvList.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
//            myQuestionAdapter.disableLoadMoreIfNotFullPage();//禁止加载
            getSwipeRefreshLayout().setEnabled(false);//禁止下拉刷新
        }
    }

    @Override
    protected void onItemClick(int position) {

    }

    @Override
    protected void loadMore() {
        refreshDone();
        loadDone(true, true);
    }

    @Override
    protected void reload() {
        loadData();
    }

    private void loadData() {
        showRefreshing();
        if (!Preferences.isLogin(this)) {
            starter().go(LoginActivity.class);
        }else {
            HttpHelper.getHome().teacher(QMap.build()
                    .put("channel", Preferences.getInstance().getChannel(mActivity).getChannel_id())
                    .create()).enqueue(new ResultCallBack<Result<List<TeacherResult>>>(mActivity) {
                @Override
                public void onSuccessCallback(int code, Result<List<TeacherResult>> body) {
                    dataList.clear();
                    final List<TeacherResult> data = body.getData();
                    for (int x=0;x<data.size();x++){
                        final List<TeacherResult.TeacherListEntity> list = body.getData().get(x).getList();
                        dataList.add(data.get(x).getCname());
                        dataList.addAll(list);
                    }
                    notifyDataSetChanged(true);
                }
                @Override
                public void onFailureCallback(int code, String msg) {
                    super.onFailureCallback(code, msg);
                    loadFailure();
                }
            });
        }

    }
}




